package com.sydx.utils;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author zoutr
 * @Description
 * @Date 2021/6/30
 * 拦截器--鼠标右键重写3个方法
 * // 要让拦截器生效，需要在spring-mvc中进行配置
 **/
public class PathInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 拿到项目路径
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://" +request.getServerName() + ":" + request.getServerPort() + path +"/";
        request.setAttribute("basePath", basePath);
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}
